
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "hfile.h"


/*
 *
 * ask_fsp(cmd) will take care of the command. it wil place it in the mmf to be read by the fsp.
 *
 */
int ask_fsp(char *cmd)
{
    int bytesWritten = 0;
    int fd;
    int result;
    char *buffer = cmd;
    char **map;  /* mmapped array of int's */
    fd = open(FILEPATH_UPLOAD, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
    if (fd == -1) {
	perror("Error opening file for writing");
	exit(EXIT_FAILURE);
    }
    bytesWritten = write(fd, buffer, strlen(buffer));

    /* Stretch the file size to the size of the (mmapped) array of ints
     */
    result = lseek(fd, FILESIZE-1, SEEK_SET);
    if (result == -1) {
	close(fd);
	perror("Error calling lseek() to 'stretch' the file");
	exit(EXIT_FAILURE);
    }

    result = write(fd, "", 1);
    if (result != 1) {
	close(fd);
	perror("Error writing last byte of the file");
	exit(EXIT_FAILURE);
    }

    /* Now the file is ready to be mmapped.
     */
    map = mmap(0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
	close(fd);
	perror("Error mmapping the file");
	exit(EXIT_FAILURE);
    }

    return 0;
}//end ask_mmf



//char cBuff_dir[MAXLEN_DIR];
//receive_data()
//send_data()


/*
void send_data(int sdClient, char data, char file)
{
  

  //ask_fsp("OPEN bsafddfsa");
    //read_mmap
    //while data is not empty; send chunks
    if(send(sdClient, data, strlen(data),0 ))
    {
        perror("send");
    }

}*/



//client_quit()


//cd(char dirname[])

/*int change_dir(char dir[MAXLEN_DIR])
{

    chdir(dir);
    if(getcwd(cBuff_dir, MAXLEN_DIR) == 0)
    {
        perror("getcwd");
        return -1;
    }
    printf("changed dir is:%s\n",cBuff_dir);
}

char get_dir()
{
    char* l
    bzero(cBuff_dir, MAXLEN_DIR);
    if(getcwd(cBuff_dir, MAXLEN_DIR) == 0)
    {
        perror("getcwd");
        return -1;
    }

    printf("curr dir is:%s\n",cBuff_dir);

    return(cBuff_dir);
}*/

//list()
//mkdir()
//delfile()
